package id.co.rho.scoring.cid.server.dao.impl;

import id.co.rho.scoring.cid.domain.WebSession;
import id.co.rho.scoring.cid.server.dao.LoginDao;

import org.springframework.stereotype.Component;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: frizky
 * Date: 10/17/11
 * Time: 2:25 PM
 */
@Component
public class LoginDaoImpl implements LoginDao {
    @PersistenceContext
    EntityManager entityManager;

    @Override
    public WebSession findWebSessionBySessionId(String sessionId) {
        List xsessionId = entityManager.createQuery("select webSession from WebSession webSession where webSession.sessionId = :xsessionId").setParameter("xsessionId", sessionId).getResultList();
        if (xsessionId.size() > 0) {
            return (WebSession) xsessionId.get(0);
        }
        return null;
    }


}
